#ifndef USERWINDOW_H
#define USERWINDOW_H

#include <QMainWindow>
#include <QTimer>
#include <QLabel>
#include <QDateTime>
#include <QString>
#include <QListWidgetItem>
#include <QCloseEvent>
#include <QHBoxLayout>
#include <QImage>
#include <QMap>

#include <unordered_map>

#include "device_header/deviceadddialog.h"
#include "device_header/deviceitemwidget.h"
#include "device_header/devicedeldialog.h"

#include "visual_header/plotwidget.h"
#include "backup_header/backupdialog.h"
#include "query_header/querydialog.h"

namespace Ui {
class UserWindow;
}

class UserWindow : public QMainWindow
{
    Q_OBJECT

private:
    QLabel *deviceLabel;
    DeviceAddDialog *add_dialog;
    DeviceDelDialog *del_dialog;
    BackUpDialog *backup_dialog;
    QueryDialog *query_dialog;
    QMap<QListWidgetItem*, DeviceItemWidget*> item_mp;
    std::unordered_map<QString, QPair<QListWidgetItem*, DeviceItemWidget*>> mp;
    std::unordered_map<QString, PlotWidget*> tab_mp;   // ip -> tab
    QTimer *release;

public:
    explicit UserWindow(QWidget *parent = nullptr);
    ~UserWindow();

private:
    void init_window();

    void close_all();

    void show_status();

private slots:
    void acquireOne(Message msg);

    void closeOne(QString mac);

    void showOne(QListWidgetItem *item);

    void recv_backup_cloud(const QString& ip);

    void recv_backup_local(const QPair<QString, QString>& pair);

    void recv_clearBuf(const QString& ip);

protected:
    void closeEvent(QCloseEvent *event) override;

private slots:
    void on_action_add_triggered();

    void on_action_del_triggered();

    void on_action_data_triggered();

    void on_action_query_triggered();

private:
    Ui::UserWindow *ui;
};

#endif // USERWINDOW_H
